package com.cndw.kungfu.model.activity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cndw.kungfu.dao.LotteryDao;
import com.cndw.kungfu.domain.LotteryLog;
import com.cndw.kungfu.domain.LotteryMode;
import com.cndw.kungfu.ext.TimeProcesser;

@Component
public class LotteryManager {
	@Autowired
	private LotteryDao dao;

	private static List<LotteryLog> carnivalLogsCache = null;

	public List<LotteryLog> getCarnivalLogsCache(boolean init) {
		if (init || carnivalLogsCache == null) {
			carnivalLogsCache = getLotteryLogs(51, 0, 20, 2);
		}
		return carnivalLogsCache;
	}

	public List<LotteryMode> getLotteryModesDB() {
		try {
			return dao.getLotterys();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public boolean isertLog(int type, long playerId, String playerName, int donType, int donNum, int maxLevel, String awards, int gold) {
		try {
			dao.insert(type, playerId, playerName, donType, donNum, maxLevel, awards, TimeProcesser.getUnixTime(), gold);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;

	}

	public List<LotteryLog> getLotteryLogs(int type, long playerId, int limit, int minLevel) {
		try {
			return dao.selectLogs(type, playerId, limit, minLevel);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public int setTotal(long playerId, int type, int beginTime, int endTime) {
		try {
			return dao.setTotal(playerId, type, beginTime, endTime);
		} catch (NullPointerException e) {

		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
}
